import request from '../request'
import type { TaskVO, TaskDTO, TaskQueryParams } from '@/types/task'
import type { PageResult } from '@/types/api'

export const taskApi = {
  // 分页查询任务列表
  getTaskPage: (params: TaskQueryParams) => {
    return request<PageResult<TaskVO>>({
      url: '/v1/tasks/page',
      method: 'get',
      params: {
        ...params,
        classIds: params.classIds?.join(','),
        page: params.page ?? 0,
        size: params.size ?? 20
      }
    })
  },

  // 创建任务
  create: (data: TaskDTO) => {
    return request({
      url: '/v1/tasks',
      method: 'post',
      data
    })
  },

  // 获取任务详情
  getById: (id: number) => {
    return request<TaskVO>({
      url: `/v1/tasks/${id}`,
      method: 'get'
    })
  },

  // 更新任务
  update: (id: number, data: TaskDTO) => {
    return request({
      url: `/v1/tasks/${id}`,
      method: 'put',
      data
    })
  },

  // 删除任务
  delete: (id: number) => {
    return request({
      url: `/v1/tasks/${id}`,
      method: 'delete'
    })
  }
} 